using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;

namespace TST.WebParts.Shared.WebControls
{
    public class ListItemHelper
    {
        /// <summary>
        /// this function sorts ListItemCollections
        /// </summary>
        /// <param name="items"></param>
        /// <param name="Descending"></param>
        public static void SortListItems(ListItemCollection items, bool Descending)
        {
            System.Collections.Generic.List<ListItem> list = new System.Collections.Generic.List<ListItem>();
            foreach (ListItem i in items)
            {
                list.Add(i);
            }

            if (Descending)
            {
                list.Sort(delegate(ListItem x, ListItem y) { return y.Text.CompareTo(x.Text); });
            }
            else
            {
                list.Sort(delegate(ListItem x, ListItem y) { return x.Text.CompareTo(y.Text); });
            }
            items.Clear();
            items.AddRange(list.ToArray());
        }
    }
}
